"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/3/6 9:56
@Description :  将class自定义对象类型数据写出到文本

python中的内置模块json不支持将class类型的数据直接转换为json字符串
"""

class Student:
    name = None
    age = None
    sex = None

    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

    def __str__(self):
        return f'{self.name},{self.age} ,{self.sex} '


student = Student('张三', 20, '男')
print(student)

student_dict = student.__dict__
print(student_dict)
import  json
with open('dir01/student_class.json', 'w') as f:
    f.write(json.dumps(student_dict))
